<?php


namespace app\common;


class ArrayFunction
{

    /**判断是几维数组
     * @param $vDim
     * @return int
     */
    /**判断是几维数组
     * @param $vDim
     * @return int
     */
    public static function level($arg = [])
    {

        if(is_array($arg) || is_object($arg)){
            $max1 = 0;
            foreach($arg as $item1)
            {
                $t1 =self::level($item1);
                if( $t1 > $max1) $max1 = $t1;
            }
            return ($max1 + 1);
        }
        else
        {
            return 0;
        }

    }
//    public static function level($arg = [])
//    {
//
//        if(is_array($arg) || is_object($arg)){
//            $max1 = 0;
//            foreach($arg as $item1)
//            {
//                $t1 =self::level($item1);
//                if( $t1 > $max1) $max1 = $t1;
//            }
//            return ($max1 + 1);
//        }
//        else
//        {
//            return 0;
//        }
//
//    }

    /**
     * @param string $time
     * @param string $format
     * @return array
     * 获取周日期
     */
    public static function week($time = '', $format = 'Y-m-d')
    {

        $time = $time != '' ? $time : time();
        $week = date('w', $time);
        $date = [];
        $week_args = [1 => '周一', 2 => '周二', 3 => '周三', 4 => '周四', 5 => '周五', 6 => '周六', 7 => '周日'];
        for ($i = 1; $i <= 7; $i++) {
            $date[$i]['num'] = $i;
            $date[$i]['week'] = $week_args[$i];
            $date[$i]['date_time'] = date($format, strtotime('+' . ($i - $week) . ' days', $time));
        }
        return array_values($date);
    }
}